﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using Microsoft.VirtualEarth.MapControl;
using SomethingSpacial.ViewModel;

namespace SomethingSpacial.Views.Default
{
    public partial class ShowDirections : ChildWindow
    {
        public ShowDirections()
        {
            InitializeComponent();
            AddPushpin(ShowDirectionsViewModel.Latitude, ShowDirectionsViewModel.Longitude, ShowDirectionsViewModel.Size);
        }

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void AddPushpin(double latitude, double longitude, double size)
        {
            // pushpin image
            Image i = new Image();
            i.Source = new BitmapImage(new Uri("../Images/pushpin.png", UriKind.Relative));
            i.Width = size;
            i.Height = size;
            //            i.MouseEnter += new MouseEventHandler(i_MouseEnter);
            //           i.MouseLeave += new MouseEventHandler(i_MouseLeave);

            // set Map position before adding to Map Control
            i.SetValue(MapLayer.MapPositionProperty, new Microsoft.VirtualEarth.MapControl.Location(latitude, longitude));
            i.SetValue(MapLayer.MapPositionMethodProperty, PositionMethod.Center);

            (MyMap.FindName("PushpinLayer") as MapLayer).AddChild(i);

            Location currentLocation = new Location(latitude, longitude);

            // move map to last location 
            MyMap.View = new MapViewSpecification(currentLocation, 13);
        }

    }
}
